package pta.test10.自定义异常;

import java.util.Scanner;
class IllegalNameException extends Exception{
    public IllegalNameException(String message){
        super(message);
    }
}

class IllegalScoreException extends Exception{
    public IllegalScoreException(String message) {
        super(message);
    }
}
class Student {
    private String name;
    private int score;

    public String getName() {
        return name;
    }

    public void setName(String name) throws IllegalNameException {
        if(name.charAt(0)>='0'&&name.charAt(0)<='9'){
            throw new IllegalNameException("the first char of name must not be digit, name=" + name);
        }
        this.name = name;
    }

    public int setScore(int score) throws IllegalScoreException {
        if(score<0||score>100){
            throw new IllegalScoreException("score out of range, score=" + score);
        }
        this.score = score;
        return score;
    }


    @Override
    public String toString() {
        return "Student [name="+name+", score="+score+"]";
    }

}
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            String str = sc.next();
            if("new".equals(str)){
                try {
                    String name = sc.next();
                    int score = sc.nextInt();
                    Student stu = new Student();
                    stu.setName(name);
                    stu.setScore(score);
                    System.out.println(stu.toString());
                } catch (IllegalNameException e) {
                    System.out.println(e);
                } catch (IllegalScoreException e) {
                    System.out.println(e);
                } catch (Exception e) {
                    System.out.println("java.util.NoSuchElementException");
                }
            }else{
                break;
            }
        }
        System.out.println("scanner closed");
    }
}